package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.SignInHistory;
import cn.wolfcode.trip.base.mapper.SignInHistoryMapper;
import cn.wolfcode.trip.base.service.ISignInHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
@Service
public class SignInHistoryServiceImpl implements ISignInHistoryService {

    @Autowired
    private SignInHistoryMapper signInHistoryMapper;
    @Override
    public List<SignInHistory> queryByUserId(Long userId) {
        return signInHistoryMapper.selectByUserId(userId);
    }

    @Override
    public void save(SignInHistory signInHistory) {
        signInHistoryMapper.insert(signInHistory);
    }

    @Override
    public List<Integer> queryDaysByMonth(String strMonth,Long userId) {
        List<Date> dates = signInHistoryMapper.selectDaysByMonth(strMonth, userId);
        List<Integer> list = new ArrayList<>();
        Calendar calendar = Calendar.getInstance();
        for (Date date1 : dates) {
            calendar.setTime(date1);
            //获取日期中的天,加入到集合中
            list.add(calendar.get(Calendar.DAY_OF_MONTH));
        }
        return list;
    }
}
